﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using LibNiconico.NiconicoApi.Internal;
using LibNiconico.NiconicoApi.Extentions;

namespace LibNiconico.NiconicoApi.HeartBeat
{
    /// <summary>
    /// ニコニコハートビート
    /// </summary>
    public sealed class NicoHeartBeat
    {
        /// <summary>
        /// 視聴者数
        /// </summary>
        public int WatchCount { get; private set; }

        /// <summary>
        /// コメント数
        /// </summary>
        public int CommentCount { get; private set; }

        /// <summary>
        /// チケット
        /// </summary>
        public string Ticket { get; private set; }

        /// <summary>
        /// サーバ時間
        /// </summary>
        public DateTime Time { get; internal set; }

        /// <summary>
        /// ドキュメント解析
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public static NicoHeartBeat Parse(XDocument document)
        {
            XElement element = document.Element("heartbeat");
            NicoHeartBeat rslt = new NicoHeartBeat
            {
                WatchCount = XElementExtention.GetElementAsInt(element,"watchCount"),
                CommentCount = XElementExtention.GetElementAsInt(element,"commentCount"),
                Ticket = XElementExtention.GetElementAsString(element,"ticket")
                

            };

            return rslt;

        }

    
    }
}
